﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
public partial class administrator_uc_admin_r_products : UserControl
{
    public DataTable dt = null;
    public static string sortexpression = string.Empty;
    public static string sortdirection = string.Empty;

    bool mostView = false;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CommonBLL.SetPermissionColumns(lt_report, Request.QueryString["mod"].ToString());
            mostView = true;
            DataTable dtproducts = new CmsBLL().GetProductsByMostView();
            lt_report.Text = new CmsBLL().Reports_ProductRender(mostView, dtproducts,"CountView");  
        }
        drd_OrderStatus.AutoPostBack = true;
        drd_OrderStatus.SelectedIndexChanged += new EventHandler(drd_OrderStatus_SelectedIndexChanged);
    }

    void drd_OrderStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (drd_OrderStatus.SelectedValue.Equals("View"))
        {
            txtFromDate.Text = string.Empty;
            txtToDate.Text = string.Empty;
            txtFromDate.Enabled = false;
            txtToDate.Enabled = false;
        }
        else {
            txtFromDate.Enabled = true;
            txtToDate.Enabled = true;
        }
    }


    protected void btn_view_Click(object sender, EventArgs e)
    {

        //txtFromDate.Text.Trim(), txtToDate.Text.Trim()

        DataTable dtproducts = new DataTable();
        string columName = string.Empty;
        if (drd_OrderStatus.SelectedValue.Equals("View"))
        {
            mostView = true;
            columName = "CountView";
            dtproducts = new DataTable();
            dtproducts = new CmsBLL().GetProductsByMostView();
        }
        else
        {
            mostView = false;
            columName = "Buy";
            dtproducts = new DataTable();
            dtproducts = new CmsBLL().GetProductsByMostBuy(mostView, txtFromDate.Text.Trim(), txtToDate.Text.Trim());
        }
        if (dtproducts.Rows.Count > 0)
        {
            lt_report.Text = new CmsBLL().Reports_ProductRender(mostView, dtproducts, columName);
        }
        else {
            lt_report.Text = "No data to load!";
        }
    }
}